package com.apes.fn.server.pickUpCar.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import org.springframework.stereotype.Component;

/**
 * Creator: zouyc
 * CreateDate: 2020-12-08 16:02
 * Description:
 **/
@Component
public class PickUpCarDao extends ApesDao {
    /**
     * 查询提前交车不符合单据
     * @param param
     * @return
     */
    public JSONArray qryAvanceOrder(JSONObject param) {
        String sSQL = " SELECT DISTINCT A.ID, A.STATE,A.SOURCE_FROM, A.SOURCE_BUSINESS_TYPE FROM SER_SERVICE_PLAN A, SER_SERVICE_PLAN_ITEM B "
                    + " WHERE A.ID = B.SERVICE_PLAN_ID AND A.STATE IN ('qualityTest', 'confirm') AND A.BELONG_DEPT_ID = :DEPT AND A.FN_CUSTOMER_EXPAND_ID = :FNCUSTOMEREXPAND "
                    + " AND NOT EXISTS (SELECT 1 FROM SER_MAINTENANCE_ORDER Z WHERE Z.SERVICE_PLAN_ITEM = B.ID AND Z.LOCK_STATE = 1) ";
        return toJSONArray(find(sSQL, param));
    }

    /**
     * 查询当前门店下该车牌的接车单
     * @param param
     * @return
     */
    public JSONArray qryPickByCarLicenseAndDept(JSONObject param) {
        String sSQL = " select TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') CREATE_DATE,\n" +
                "       ID,\n" +
                "       STATE,\n" +
                "       creator_id,\n" +
                "       GET_PARTY_NAME(creator_id, 'Employee')          creator_NAME,\n" +
                "       A.MILEAGE,A.FUEL_METER,A.KEY_NUMBER,A.NOTE\n" +
                "from FN_PICK_UP_CAR A\n" +
                "where LICENSE_NUMBER = :carLicense\n" +
                "and DEPT_ID = :dept";
        return toJSONArray(find(sSQL, param));
    }
    /**
     * 查询当前门店下该车牌的接车单
     * @param param
     * @return
     */
    public JSONArray qryPickItemsByCarLicenseAndDept(JSONObject param) {
        String sSQL = " select TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD HH24:MI:SS') CREATE_DATE,\n" +
                "       ID,\n" +
                "       STATE,\n" +
                "       creator_id,\n" +
                "       GET_PARTY_NAME(creator_id, 'Employee')          creator_NAME,\n" +
                "       A.MILEAGE,A.FUEL_METER,A.KEY_NUMBER,A.NOTE\n" +
                "from FN_PICK_UP_CAR A\n" +
                "where LICENSE_NUMBER = :CarLicense\n" +
                "and DEPT_ID = :Dept";
        return toJSONArray(find(sSQL, param));
    }
}
